<?php
/**
 * Created by PhpStorm.
 * User: lizx
 * Date: 2018/1/29
 * Time: 17:23
 */

namespace app\common;

class Instance
{
    static $_instance = [];

    /**
     * 创建实例
     * @param $name
     * @param bool $flush
     * @return mixed
     */
    public static function getInstance($name, $flush)
    {
        if ($flush || !isset(self::$_instance[$name])) {
            self::$_instance[$name] = new $name;
        }
        return self::$_instance[$name];
    }

    /**
     * 销毁实例
     * @param $name
     */
    public static function destructInstance($name)
    {
        if (isset(self::$_instance[$name])) {
            unset(self::$_instance[$name]);
        }
    }
}